
var VERSION = '1.0.0';

var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var TypedocWebpackPlugin = require('typedoc-webpack-plugin');
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');
var HtmlWebpackPlugin = require('html-webpack-plugin');

var commonConfig = require('./webpack.common.js');
const ENV = process.env.ENV = process.env.NODE_ENV = 'production';
var utils = require('./utils');
var webpackConfig = function (options) {
    return webpackMerge(commonConfig({ env: ENV }), {
         entry: entries(utils.root('src') + '/*'),
        //入口文件输出配置
        output: {
            path: 'dist/',
            filename: 'js/[name]_' + VERSION + '_[chunkHash:8]' + '.bundle.js',
            publicPath: '/wit/',//配置虚拟目录
            chunkFilename: 'js/[name]_' + VERSION + '_[chunkHash:8]' + '.bundle.js',
        },

          plugins: [
           // new webpack.BannerPlugin('Owned by WIT'),

            //commonsPlugin,

            new webpack.optimize.CommonsChunkPlugin({ //common file
                name: ['ZZpolyfills', 'XXapp'].reverse()
            }),

            new HtmlWebpackPlugin({
                template: 'src/index.html'
            }),

            // new HtmlWebpackPlugin({
            //     filename: 'notfound.html',
            //     template: './src/notfound.html'
            // }),

            new CopyWebpackPlugin([
                 {
                    from: './src/lib/lib.js',
                    to: 'js/lib.js',
                    force: true
                },
                {
                    from: './src/app.config.js',
                    force: true
                },
                {
                    from: './src/config',
                    to: 'config',
                    force: true
                }
            ]),

            new ExtractTextPlugin("assets/[name].css"),

            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('../src/lib/manifest.json'),                
            }),

            // new TypedocWebpackPlugin({
            //     name: 'WIT',
            //     mode: 'file',
            //     includeDeclarations: false,
            //     ignoreCompilerErrors: true,
            // })
        ]
    });
};

function entries(globPath) {
    var entries = {
        'ZZpolyfills': './src/polyfills.ts',      
        'XXapp': './src/main.ts',
        'ZZstyle': './src/assets/lib.scss',
        'boot': './src/assets/boot.scss',

    };
    //utils.getEntries(globPath, entries);
    return entries;
}

module.exports = webpackConfig;